package cn.edu.scau.dropship.ServiceImpl;

import cn.edu.scau.dropship.entity.Classification;
import cn.edu.scau.dropship.entity.ClassificationExample;
import cn.edu.scau.dropship.mapper.ClassificationMapper;
import cn.edu.scau.dropship.service.ClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassificationServiceImpl implements ClassificationService {
    @Autowired
    private ClassificationMapper classificationMapper;

    @Override
    public long countByExample(ClassificationExample example) {
        return classificationMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(ClassificationExample example) {
        return classificationMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return classificationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Classification record) {
        return classificationMapper.insert(record);
    }

    @Override
    public int insertSelective(Classification record) {
        return classificationMapper.insertSelective(record);
    }

    @Override
    public List<Classification> selectByExample(ClassificationExample example) {
        return classificationMapper.selectByExample(example);
    }

    @Override
    public Classification selectByPrimaryKey(Integer id) {
        return classificationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Classification record, ClassificationExample example) {
        return classificationMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Classification record, ClassificationExample example) {
        return classificationMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Classification record) {
        return classificationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Classification record) {
        return classificationMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Classification> selectAll() {
        ClassificationExample classificationExample=new ClassificationExample();
        ClassificationExample.Criteria criteria=classificationExample.createCriteria();
        criteria.andIdIsNotNull();
        return classificationMapper.selectByExample(classificationExample);
    }

    @Override
    public Classification selectByName(String name) {
        ClassificationExample classificationExample=new ClassificationExample();
        ClassificationExample.Criteria criteria=classificationExample.createCriteria();
        criteria.andNameEqualTo(name);
        List<Classification> list=classificationMapper.selectByExample(classificationExample);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
